package bbb.sss;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class CountMap extends HashMap<Integer, Integer> {

	private static final long serialVersionUID = 1L;

	public CountMap(int count) {
		super();
		for (int i = 1; i <= count; i++) {
			this.put(i, 0);
		}
	}

	public List<Entry<Integer, Integer>> keySortedList() {
		ArrayList<Entry<Integer, Integer>> l = new ArrayList<Entry<Integer, Integer>>(
				this.entrySet());
		Collections.sort(l, new Comparator<Map.Entry<Integer, Integer>>() {
			public int compare(Map.Entry<Integer, Integer> o1,
					Map.Entry<Integer, Integer> o2) {
				return (o1.getKey() - o2.getKey());
			}
		});
		return l;
	}
	
	public List<Entry<Integer, Integer>> valueSortedList() {
		ArrayList<Entry<Integer, Integer>> l = new ArrayList<Entry<Integer, Integer>>(
				this.entrySet());
		Collections.sort(l, new Comparator<Map.Entry<Integer, Integer>>() {
			public int compare(Map.Entry<Integer, Integer> o1,
					Map.Entry<Integer, Integer> o2) {
				return (o1.getValue() - o2.getValue());
			}
		});
		return l;
	}
	
}
